<?php
class Training_FilterController extends Zendvn_Controller_Action{
	
	protected $_arrParam;
	
	public function init(){
		$this->_arrParam = $this->_request->getParams();
	}
	
	
	public function zip3Action(){
		$options = array(
							'adapter'=>'zip',
							'options' => array(
												'archive'=> FILE_PATH . '/zip/abc.zip',
												'password'=> '123456',
		
												)
						);
		$filter = new Zend_Filter_Compress($options);
		$filter->compress(FILE_PATH . '/test/Capture.GIF');
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function unzip2Action(){
		$options = array(
							'adapter'=>'zip',
							'options' => array(
												'target'=> FILE_PATH . '/unzip/zip',
												'password'=> '123456',
		
												)
						);
		$filter = new Zend_Filter_Decompress($options);
		$filter->decompress(FILE_PATH . '/test/Capture.zip');
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function unzipAction(){
		
		/*$optionZip = array('target'=> FILE_PATH . '/unzip');
		$filter = new Zend_Filter_Compress_Zip($optionZip);
		$filter->decompress(FILE_PATH . '/zip/picture.zip');*/
		$options = array(
							'adapter'=>'zip',
							'options' => array('target'=> FILE_PATH . '/unzip')
						);
		$filter = new Zend_Filter_Decompress($options);
		$filter->decompress(FILE_PATH . '/folder.zip');
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function zip2Action(){
		$options = array(
						'adapter' => 'zip',
						'options' => array('archive'=> FILE_PATH . '/folder.zip')
						);
		$filter = new Zend_Filter_Compress($options);
		$filter->compress(FILE_PATH . '/zip/');
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function zipAction(){
		//
		
		/*$optionZip = array('archive'=> FILE_PATH . '/zip/picture.zip');
		$filter = new Zend_Filter_Compress_Zip($optionZip);
		$filter->compress(FILE_PATH . '/test/Capture.GIF');*/
		
		$options = array(
						'adapter' => 'gz',
						'options' => array('archive'=> FILE_PATH . '/zip/picture2.gz')
						);
		$filter = new Zend_Filter_Compress($options);
		$filter->compress(FILE_PATH . '/test/Capture.GIF');
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function ex1Action(){
		$str = '   Khóa    học Zend Framework cung cấp     những kiến thức cơ bản    về ZF ở đây Đ Ư Â';
		$filter = new Zendvn_Filter_RemoveCircumflex();
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Filter: ' . $result;
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function multiAction(){
		$str = '   Khóa    học Zend Framework cung cấp     những kiến thức cơ bản    về ZF';
		$filter = new Zend_Filter();
		$filter->addFilter(new Zend_Filter_StringToLower('utf-8'))
			   ->addFilter(new Zend_Filter_StringTrim())
			   ->addFilter(new Zend_Filter_PregReplace('#\s+#','-'))
				;
		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Filter: ' . $result;
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function word4Action(){
		$str = '   Khóa    học Zend Framework cung cấp     những kiến thức cơ bản    về ZF';
		
	/*	$filter = new Zend_Filter_Word_SeparatorToSeparator(' ', '-');
		
		$result = $filter->filter($str);*/
		$option = array('match'=> '#\s+#','replace'=> '-');
		$filter = new Zend_Filter_PregReplace($option);
		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Filter: ' . $result;
		$this->_helper->viewRenderer->setNoRender();
		
	}
	
	
	public function word3Action(){
		$str = '   Khóa    học Zend Framework cung cấp     những kiến thức cơ bản    về ZF';
		
		$filter = new Zend_Filter_Word_SeparatorToSeparator('Zend', '<a href="#">Zend</a>');
		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Filter: ' . $result;
		$this->_helper->viewRenderer->setNoRender();
		
	}
	
	public function word2Action(){
		$str = '   Khóa    học Zend Framework cung cấp     những kiến thức cơ bản    về ZF';
		$str = 'Zend Filter word CamelCaseToDash';
		$str = 'Zend Filter word camel-case-to-dash';
		
//		$filter = new Zend_Filter_Word_CamelCaseToSeparator();		
//		$filter = new Zend_Filter_Word_CamelCaseToUnderscore();		
		$filter = new Zend_Filter_Word_DashToCamelCase();		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Filter: ' . $result;
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function wordAction(){
		$str = '   Khóa    học Zend Framework cung cấp     những kiến thức cơ bản    về ZF';
		$str = 'Zend Filter word CamelCaseToDash';
		
		$filter = new Zend_Filter_Word_CamelCaseToDash();		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Filter: ' . $result;
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function separatorAction(){
		$str = '   Khóa    học Zend Framework cung cấp     những kiến thức cơ bản    về ZF';
		
		$filter = new Zend_Filter_Word_SeparatorToDash(' ');		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Filter: ' . $result;
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function tagAction(){
		
		//$str = '<B>My content</B>';
		$str = 'This <h2>contains</h2> <a href="http://example.com">no ending tag</a>';
		
		$filter = new Zend_Filter_StripTags();		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Result: ' . $result;
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function index6Action(){
		
		$source = 'Xin vui lòng chờ trong giây lát. Trình duyệt sẽ tự động chuyển đến trang chủ.';
		
		$filter = new Zend_Filter_StringToUpper('utf-8');
		//$filter = new Zend_Filter_StringToUpper(array('encoding'=>'utf-8'));
		$filter = new Zend_Filter_StringToLower(array('encoding'=>'utf-8'));
		$result = $filter->filter($source);
		
		echo '<br>Source: ' . $source;
		echo '<br>Result: ' . $result;
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function index5Action(){
		
		$source = 'This is a test';
		
		$filter = new Zend_Filter_Callback('strtolower');
		$result = $filter->filter($source);
		
		echo '<br>Source: ' . $source;
		echo '<br>Result: ' . $result;
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function index4Action(){
		
		$source = 'file:///D:/zf-api-1.11/core/index.html';
		
		$filter = new Zend_Filter_BaseName();
		$result = $filter->filter($source);
		
		echo '<br>Source: ' . $source;
		echo '<br>Result: ' . $result;
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function index3Action(){
		
		$source = 'file:///D:/zf-api-1.11/core/index.html';
		$source = 'http://localhost/zf010/training/filter/index3';
	
		$filter = new Zend_Filter_Dir();
		$result = $filter->filter($source);
		
		echo '<br>Source: ' . $source;
		echo '<br>Result: ' . $result;
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function index2Action(){
		
		$source = 'sdfghjkl; 2@#$%^&*()_ GHJKL';
		//$filter = new Zend_Filter_Alpha();
		$filter = new Zend_Filter_Alpha(true);
		$result = $filter->filter($source);
		
		echo '<br>Source: ' . $source;
		echo '<br>Result: ' . $result;
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function indexAction(){
		
		$source = 'sdfghjkl; 2@#$%^&*()_ GHJKL';
		//$filter = new Zend_Filter_Alnum();
		$filter = new Zend_Filter_Alnum(true);
		$result = $filter->filter($source);
		
		echo '<br>Source: ' . $source;
		echo '<br>Result: ' . $result;
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
}